package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TSendReceiveInfo;
import com.ruoyi.system.service.ITSendReceiveInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发收信息Controller
 * 
 * @author wzy
 * @date 2024-08-30 10:43:11
 */
@RestController
@RequestMapping("/system/sendrece")
public class TSendReceiveInfoController extends BaseController
{
    @Autowired
    private ITSendReceiveInfoService tSendReceiveInfoService;

    /**
     * 查询发收信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:sendrece:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSendReceiveInfo tSendReceiveInfo)
    {
        startPage();
        List<TSendReceiveInfo> list = tSendReceiveInfoService.selectTSendReceiveInfoList(tSendReceiveInfo);
        return getDataTable(list);
    }

    /**
     * 导出发收信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:sendrece:export')")
    @Log(title = "发收信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSendReceiveInfo tSendReceiveInfo)
    {
        List<TSendReceiveInfo> list = tSendReceiveInfoService.selectTSendReceiveInfoList(tSendReceiveInfo);
        ExcelUtil<TSendReceiveInfo> util = new ExcelUtil<TSendReceiveInfo>(TSendReceiveInfo.class);
        util.exportExcel(response, list, "发收信息数据");
    }

    /**
     * 获取发收信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sendrece:query')")
    @GetMapping(value = "/{sendReceiveId}")
    public AjaxResult getInfo(@PathVariable("sendReceiveId") Long sendReceiveId)
    {
        return success(tSendReceiveInfoService.selectTSendReceiveInfoBySendReceiveId(sendReceiveId));
    }

    /**
     * 新增发收信息
     */
    @PreAuthorize("@ss.hasPermi('system:sendrece:add')")
    @Log(title = "发收信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSendReceiveInfo tSendReceiveInfo)
    {
        tSendReceiveInfo.setCreateBy(getNickName());
        return toAjax(tSendReceiveInfoService.insertTSendReceiveInfo(tSendReceiveInfo));
    }

    /**
     * 修改发收信息
     */
    @PreAuthorize("@ss.hasPermi('system:sendrece:edit')")
    @Log(title = "发收信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSendReceiveInfo tSendReceiveInfo)
    {
        tSendReceiveInfo.setUpdateBy(getNickName());
        return toAjax(tSendReceiveInfoService.updateTSendReceiveInfo(tSendReceiveInfo));
    }

    /**
     * 删除发收信息
     */
    @PreAuthorize("@ss.hasPermi('system:sendrece:remove')")
    @Log(title = "发收信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sendReceiveIds}")
    public AjaxResult remove(@PathVariable Long[] sendReceiveIds)
    {
        return toAjax(tSendReceiveInfoService.deleteTSendReceiveInfoBySendReceiveIds(sendReceiveIds));
    }

    /**
     * 获取发收信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:sendrece:query')")
    @GetMapping(value = "/ext/{mobile}")
    public AjaxResult getOneInfo(@PathVariable("mobile") String mobile)
    {
        return success(tSendReceiveInfoService.selectTSendReceiveInfoByMobile(mobile));
    }
}
